using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace ProjectCodeS.Models
{
    public class ProjectCodeSContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>()
                .HasMany(u => u.UserRoles).WithMany(r => r.Users)
                .Map(t => t.MapLeftKey("UserId")
                    .MapRightKey("UserRoleId")
                    .ToTable("UsersUserRoles"));

            modelBuilder.Entity<ChargeCategory>()
                .HasMany(c => c.ServiceTypes).WithMany(s => s.ChargeCategories)
                .Map(t => t.MapLeftKey("ChargeCategoryId")
                    .MapRightKey("ServiceTypeId")
                    .ToTable("ChargeCategoriesServiceTypes"));

            modelBuilder.Entity<TicketItem>()
                .HasMany(t => t.Colors).WithMany(c => c.TicketItems)
                .Map(t => t.MapLeftKey("TicketItemId")
                    .MapRightKey("ColorId")
                    .ToTable("TicketItemsColors"));

            modelBuilder.Entity<TicketItem>()
                .HasMany(t => t.Textures).WithMany(t => t.TicketItems)
                .Map(t => t.MapLeftKey("TicketItemId")
                    .MapRightKey("TextureId")
                    .ToTable("TicketItemsTextures"));
        }
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, add the following
        // code to the Application_Start method in your Global.asax file.
        // Note: this will destroy and re-create your database with every model change.
        // 
        // System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<ProjectCodeS.Models.ProjectCodeSContext>());

        public DbSet<ProjectCodeS.Models.ChargeCategory> ChargeCategories { get; set; }

        public DbSet<ProjectCodeS.Models.Client> Clients { get; set; }

        public DbSet<ProjectCodeS.Models.Company> Companies { get; set; }

        public DbSet<ProjectCodeS.Models.Item> Items { get; set; }

        public DbSet<ProjectCodeS.Models.ItemColor> ItemColors { get; set; }

        public DbSet<ProjectCodeS.Models.ItemTexture> ItemTextures { get; set; }

        public DbSet<ProjectCodeS.Models.ServiceType> ServiceTypes { get; set; }

        public DbSet<ProjectCodeS.Models.Store> Stores { get; set; }

        public DbSet<ProjectCodeS.Models.Ticket> Tickets { get; set; }

        public DbSet<ProjectCodeS.Models.TicketItem> TicketItems { get; set; }

        public DbSet<ProjectCodeS.Models.User> Users { get; set; }

        public DbSet<ProjectCodeS.Models.UserRole> UserRoles { get; set; }
    }
}